<%@page import="java.util.ArrayList"%>
<%@page import="com.entity.Student"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.LinkedHashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="<%=request.getContextPath()%>/bootstrap/4.1.3/css/bootstrap.min.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/popper.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<style type="text/css">
/* html,
body {
  height: 100%;
} */
body {
  display: -ms-flexbox;
  display: -webkit-box;
  display: flex;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  padding-top: 0px;
  padding-bottom: 0px;
  background-color: #f5f5f5;
}
</style>
<script type="text/javascript">
	function add(){
		window.open("../servlet/student.do?action=add");
	}
	
	function modify(){
		var number = $(":checkbox[name='number']:checked")[0];
		if( !number ){
			alert("请至少选中一项！");
			return ;
		}
		window.open("../servlet/student.do?action=modify&number="+$(number).val());
	}
	function del(){
		var checkeds = $(":checkbox[name='number']:checked");
		if( checkeds && checkeds.length > 0){
			
			var d = function(){ 
				var defer = $.Deferred();
				$(checkeds).each(function(){
					$(this).parent().parent().addClass("bg-danger");
					defer.resolve("");
				});
				return defer;
			};
			d().then(function(data){
				if( confirm("确定删除"+checkeds.length + "项？")){
					var values = [];
					$(checkeds).each(function(){
						values.push($(this).val());
					});
					window.open("../servlet/student.do?action=del&numbers="+values);
				}
				else{
					$(checkeds).each(function(){
						$(this).parent().parent().removeClass("bg-danger");
					});
				}
			});
			
		}
		
	}
</script>
<title>信息列表</title>
</head>



<body >
	
	<div class="card " style="height: 100%;width: 100%;">
		<div class="card-header bg-primary text-white">
			<div class="container">
				<div class="row">
					<div class="col-sm-12 col-md-6">
					<h3>学生信息列表</h3>
					</div>
					<div class="col-sm-12 col-md-6">
						<button class="btn btn-success"
							onclick="add()">添加</button>
						<button class="btn btn-info"
							onclick="modify()">修改</button>
						<button class="btn btn-danger"
							onclick="del()">删除</button>
					</div>
				</div>
			</div>
		</div>
		<div class="card-body" style="overflow: auto;">
			<div>
			</div>
			<table class="table table-striped table-hover">
				<thead class="bg-secondary text-white">
					<tr>
						<td width="40px"><input type="checkbox">
						</td>
						<td>学号</td>
						<td>姓名</td>
						<td>性别</td>
						<td>兴趣爱好</td>
					</tr>
				</thead>
				<tbody >
				<%
					List<Student> stdList = (List<Student>)application.getAttribute("stdList");
					if( stdList != null){
						for(Student std : stdList){
							String likeStr = "";
							if( std.getLike() != null ){
								likeStr = String.join(",", std.getLike());
							}
				%>
					
					<tr>
						<td><input type="checkbox" 
							name="number" value="<%=std.getNumber()%>"></td>
						<td><%=std.getNumber() %></td>
						<td><%=std.getName() %></td>
						<td><%=std.getSex() %></td>
						<td><%=likeStr%></td>
					</tr>
					
				<%
						}
					}
				%>
				</tbody>
			</table>
		
		</div>
		<div class="card-footer bg-info text-center">
			
		</div>
	</div>
</body>
</html>